package com.bitmain.mmst.web.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bitmain.mmst.domain.Miner;
import com.bitmain.mmst.feature.cache.GlobalDataBuffer;
import com.bitmain.mmst.web.dao.MacModelDao;

/**
 *
 * @author Richard - rui.wu@bitmain.com
 * @since 2016年8月26日
 * 
*/

@Service("macModelService")
public class MacModelService {
	
	@Autowired
	private MacModelDao macModelDao;

	public int add(Miner miner) {
		try {
			if(macModelDao.countByMac(miner)>0){
				System.out.println("内存里有相同的mac");
				return 0;
			}
			System.out.println("内存里无相同的mac");
			macModelDao.insert(miner);
			GlobalDataBuffer.putMacType(miner.getMac(), miner.getModel());
			return 1;
		} catch (Exception e) {
			return -1;
		}
	}
}

